﻿namespace Sidvall.AuthorizationManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AuthorizationScopeExport : global::Sidvall.AuthorizationManager.UI.Entities.Core.BusinessBase, global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport
    {
        #region Business Members

        #region AuthorizationScopeExportId

        private System.Nullable<long> _AuthorizationScopeExportId = null;
        partial void OnBeforeAuthorizationScopeExportIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData);
        partial void OnBeforeAuthorizationScopeExportIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterAuthorizationScopeExportIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<long> AuthorizationScopeExportId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<long>>(_AuthorizationScopeExportId);
                OnBeforeAuthorizationScopeExportIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _AuthorizationScopeExportId);
                OnBeforeAuthorizationScopeExportIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("AuthorizationScopeExportId", eventData.Value, true, true, true);
                    OnAfterAuthorizationScopeExportIdPropertyChanged();
                }
            }
        }

        #endregion
        #region AuthorizationScopeId

        private long _AuthorizationScopeId = 0L;
        partial void OnBeforeAuthorizationScopeIdPropertyGet(Sidvall.Business.PropertyEventData<long> eventData);
        partial void OnBeforeAuthorizationScopeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterAuthorizationScopeIdPropertyChanged();
        public long AuthorizationScopeId
        {
            get
            {
                Sidvall.Business.PropertyEventData<long> eventData = new Sidvall.Business.PropertyEventData<long>(_AuthorizationScopeId);
                OnBeforeAuthorizationScopeIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _AuthorizationScopeId);
                OnBeforeAuthorizationScopeIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("AuthorizationScopeId", eventData.Value, true, true, true);
                    OnAfterAuthorizationScopeIdPropertyChanged();
                }
            }
        }

        #endregion
        #region CreateMissingFile

        private bool _CreateMissingFile = false;
        partial void OnBeforeCreateMissingFilePropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeCreateMissingFilePropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterCreateMissingFilePropertyChanged();
        public bool CreateMissingFile
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_CreateMissingFile);
                OnBeforeCreateMissingFilePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _CreateMissingFile);
                OnBeforeCreateMissingFilePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("CreateMissingFile", eventData.Value, true, true, true);
                    OnAfterCreateMissingFilePropertyChanged();
                }
            }
        }

        #endregion
        #region FilePath

        private string _FilePath = string.Empty;
        partial void OnBeforeFilePathPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeFilePathPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterFilePathPropertyChanged();
        public string FilePath
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_FilePath);
                OnBeforeFilePathPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _FilePath);
                OnBeforeFilePathPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("FilePath", eventData.Value, true, true, true);
                    OnAfterFilePathPropertyChanged();
                }
            }
        }

        #endregion
        #region IncludeResourceItems

        private bool _IncludeResourceItems = false;
        partial void OnBeforeIncludeResourceItemsPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeIncludeResourceItemsPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIncludeResourceItemsPropertyChanged();
        public bool IncludeResourceItems
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_IncludeResourceItems);
                OnBeforeIncludeResourceItemsPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IncludeResourceItems);
                OnBeforeIncludeResourceItemsPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IncludeResourceItems", eventData.Value, true, true, true);
                    OnAfterIncludeResourceItemsPropertyChanged();
                }
            }
        }

        #endregion
        #region IncludeUserItems

        private bool _IncludeUserItems = false;
        partial void OnBeforeIncludeUserItemsPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeIncludeUserItemsPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIncludeUserItemsPropertyChanged();
        public bool IncludeUserItems
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_IncludeUserItems);
                OnBeforeIncludeUserItemsPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IncludeUserItems);
                OnBeforeIncludeUserItemsPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IncludeUserItems", eventData.Value, true, true, true);
                    OnAfterIncludeUserItemsPropertyChanged();
                }
            }
        }

        #endregion
        #region IsEnabled

        private bool _IsEnabled = false;
        partial void OnBeforeIsEnabledPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeIsEnabledPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsEnabledPropertyChanged();
        public bool IsEnabled
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_IsEnabled);
                OnBeforeIsEnabledPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabled);
                OnBeforeIsEnabledPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IsEnabled", eventData.Value, true, true, true);
                    OnAfterIsEnabledPropertyChanged();
                }
            }
        }

        #endregion
        #region XmlNode

        private string _XmlNode = string.Empty;
        partial void OnBeforeXmlNodePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeXmlNodePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterXmlNodePropertyChanged();
        public string XmlNode
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_XmlNode);
                OnBeforeXmlNodePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _XmlNode);
                OnBeforeXmlNodePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("XmlNode", eventData.Value, true, true, true);
                    OnAfterXmlNodePropertyChanged();
                }
            }
        }

        #endregion
        #region AuthorizationScope

        private AuthorizationScope _AuthorizationScope;
        partial void OnBeforeAuthorizationScopePropertyChanged(Sidvall.Business.PropertyChangeEventData<AuthorizationScope> eventData);
        partial void OnAfterAuthorizationScopePropertyChanged();
        public AuthorizationScope AuthorizationScope
        {
            get
            {
                return _AuthorizationScope;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<AuthorizationScope> eventData = new Sidvall.Business.PropertyChangeEventData<AuthorizationScope>(value, _AuthorizationScope);
                OnBeforeAuthorizationScopePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("AuthorizationScope", eventData.Value, true, true, false);
                    OnAfterAuthorizationScopePropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadAuthorizationScopeAsync

        public async System.Threading.Tasks.Task<AuthorizationScope> LoadAuthorizationScopeAsync()
        {
            return await LoadAuthorizationScopeAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<AuthorizationScope> LoadAuthorizationScopeAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeExportManager.LoadAuthorizationScopeAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.AuthorizationScope;
        }
        public AuthorizationScope LoadAuthorizationScope(AuthorizationScope item)
        {
            LoadInstanceField("AuthorizationScope", item, true, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public AuthorizationScopeExport Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public AuthorizationScopeExport Copy()
        {
            return Copy(null);
        }
        public AuthorizationScopeExport Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new AuthorizationScopeExport();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(AuthorizationScopeExport destination, global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport source, Sidvall.Data.CopySettings copySettings);
        private void Import(AuthorizationScopeExport destination, global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(AuthorizationScopeExport destination, AuthorizationScopeExport source, Sidvall.Data.CopySettings copySettings);
        private void Import(AuthorizationScopeExport destination, AuthorizationScopeExport source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<AuthorizationScopeExport> SaveItemAsync()
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeExportManager.SaveItemAsync(this);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeExport> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeExportManager.SaveItemAsync(this, mode);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeExport> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeExportManager.SaveItemAsync(this, settings);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeExport> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.DataPortal.AuthorizationScopeExportManager.SaveItemAsync(this, settings, strategyContext, objectParameters);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.Initialize(this, settings);
        }

        #endregion
        
        #region IAuthorizationScopeExport Members

        System.Nullable<long> global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport.AuthorizationScopeExportId
        {
            get
            {
                return this._AuthorizationScopeExportId;
            }
            set
            {
                this._AuthorizationScopeExportId = value;
            }
        }
        long global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport.AuthorizationScopeId
        {
            get
            {
                return this._AuthorizationScopeId;
            }
            set
            {
                this._AuthorizationScopeId = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport.CreateMissingFile
        {
            get
            {
                return this._CreateMissingFile;
            }
            set
            {
                this._CreateMissingFile = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport.FilePath
        {
            get
            {
                return this._FilePath;
            }
            set
            {
                this._FilePath = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport.IncludeResourceItems
        {
            get
            {
                return this._IncludeResourceItems;
            }
            set
            {
                this._IncludeResourceItems = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport.IncludeUserItems
        {
            get
            {
                return this._IncludeUserItems;
            }
            set
            {
                this._IncludeUserItems = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport.IsEnabled
        {
            get
            {
                return this._IsEnabled;
            }
            set
            {
                this._IsEnabled = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport.XmlNode
        {
            get
            {
                return this._XmlNode;
            }
            set
            {
                this._XmlNode = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.IAuthorizationScope global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport.AuthorizationScope
        {
            get
            {
                return this._AuthorizationScope;
            }
            set
            {
                UpdateChildProperty(this._AuthorizationScope, value);
                this._AuthorizationScope = value as AuthorizationScope;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public AuthorizationScopeExport()
        {
        }

        public AuthorizationScopeExport(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}